package net.maku.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import com.wechat.pay.java.core.notification.NotificationParser;
import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@Configuration
@EnableConfigurationProperties(WxConfigProperties.class)
public class WxConfigConfiguration {
	
	@Autowired
	private WxConfigProperties properties;
	
	@Bean
	public RSAAutoCertificateConfig config() {
		 RSAAutoCertificateConfig config = new RSAAutoCertificateConfig.Builder()
	                .merchantId(properties.getMchId())
	                .privateKeyFromPath(properties.getKeyPath())
	                .merchantSerialNumber(properties.getMerchantSerialNumber())
	                .apiV3Key( properties.getApiV3Key() )
	                .build();
		 return config;
	}
	
	
	@Bean
	public JsapiServiceExtension jsapiService() {
		/*
		 RSAAutoCertificateConfig config = new RSAAutoCertificateConfig.Builder()
	                .merchantId(properties.getMchId())
	                .privateKeyFromPath(properties.getKeyPath())
	                .merchantSerialNumber(properties.getMerchantSerialNumber())
	                .apiV3Key( properties.getApiV3Key() )
	                .build();
		 //请求微信支付相关配置
		 JsapiServiceExtension service = new JsapiServiceExtension.Builder()
		                        .config(config)
		                        .signType("RSA") // 不填默认为RSA
		                        .build();
		 */
		 
		 return new JsapiServiceExtension.Builder()
                 .config(config())
                 .signType("RSA") // 不填默认为RSA
                 .build();
	}

	@Bean
	public NotificationParser notiParser() {
		return new NotificationParser(config());
	}

}




